package com.example.rotateimageview.customView;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

/**
 * author  : Liushuai
 * time    : 2021/9/13 21:43
 * desc    :
 */
public class RoundLinearLayout extends LinearLayout {

    private Path mPath = new Path();
    public RoundLinearLayout(Context context) {
        super(context);
    }


    private int dynamicLength=0;


    public int getDynamicLength() {
        return dynamicLength;
    }

    public void setDynamicLength(int dynamicLength) {
        this.dynamicLength = dynamicLength;
    }

    public RoundLinearLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public RoundLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Log.i("---onDraw-", "");
    }

    private void startAnimation() {
        ObjectAnimator objectAnimator = ObjectAnimator.ofInt(RoundLinearLayout.this, "dynamicLength", 1);
        objectAnimator.start();
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        mPath.reset();
        mPath.addRoundRect(new RectF(0,0,getMeasuredWidth(),getMeasuredHeight()),50,50f, Path.Direction.CW);

        canvas.save();
        canvas.clipPath(mPath);
        canvas.drawColor(Color.GREEN);
        super.dispatchDraw(canvas);
        canvas.restore();
    }
}
